import { CCCAgentsError } from "../CCCAgentsError";
import { StatAggregationMethod } from "../StatsRecorder";
import { Guid } from "../Utils/Guid";
import { IncomingMessage } from "./InComingMessage";
import { OutgoingMessage } from "./OutgoingMessage";
import { SideChannel } from "./SideChannel";

export class StatsSideChannel extends SideChannel {
    private static readonly kStatsSideChannelDefaultId: string = "a1d8f7b7-cec8-50f9-b78b-d3e165a78520";

    constructor() {
        super();
        this.channelId = new Guid(StatsSideChannel.kStatsSideChannelDefaultId);
    }

    
    public addStat(key: string, value: number, aggregationMethod: StatAggregationMethod): void {
        const msg = new OutgoingMessage();
        msg.writeString(key);
        msg.writeFloat32(value);
        msg.writeInt32(aggregationMethod);
        this.queueMessageToSend(msg);
    }

    onMessageReceived(msg: IncomingMessage): void {
        throw new CCCAgentsError("StatsSideChannel should never receive messages.");
    }
}